<template>
	<view>
		<view :key="'header'+headerKey" class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgColor?bgColor:SwitchCur == 1?'bg-gradual-blue-light':'none-bg text-white']">
				<view class="action" @tap="BackPage" v-if="isBack&&!isHome">
					<text class="basefont icon-left"></text>
					<text class="text-df">{{backText}}</text>
				</view>
				<view class="content-1" :style="[{top:StatusBar + 'px'}]">
					<view class="action">
						<view class="item" 
						:class="SwitchCur == 1 ? 'selected' : null "
						@tap.stop="SwitchTab(1)">关注</view>
						<view class="item"
						:class="SwitchCur == 3 ? 'selected' : null "
						@tap.stop="SwitchTab(3)">同城</view>
						<view class="item"
						 :class="SwitchCur == 2 ? 'selected' : null "
						 @tap.stop="SwitchTab(2)">
							<text>推荐</text>
						 </view>
					</view>
				</view>
				<view class="text-right" style="padding-right: 30rpx;" @tap="openSearch">
					<text class="basefont icon-search"></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onShow() {
			this.headerKey += 1;
		},
		data() {
			return {
				headerKey:0,
				StatusBar: this.$StatusBar,
				CustomBar: this.$CustomBar,
				SwitchCur: 2,
				searchText:''
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar||0;
				var CustomBar= this.CustomBar||50;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		onReady() {
			this.StatusBar=this.$StatusBar
			this.CustomBar=this.$CustomBar
			this.SwitchTab(this.SwitchCur)
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			backText: {
				type: String,
				default: ''
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			SwitchTab(val) {
				this.SwitchCur = val
				this.$emit('headerSwitch',val);
			},
			BackPage() {
				// #ifdef H5
				let a = this.$Router.back(1)
				if (a == undefined) {
				//重新定向跳转页面
					this.$Router.replaceAll({ name:'home'})
				}
				// #endif
				// #ifndef H5
				this.$Router.back(1)
				// #endif
			},
			openSearch(){
				this.$Router.push({ name:'videoSearch'})
			}
		}
	}
</script>

<style lang="scss">
.navigation-bar-capsule{
	position: absolute;
		// height: 32px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		line-height: 28px;
		height: 28px;
		font-size: 16px;
		width: 70px;
		left: 10px;
		//background-color: rgba(255,255,255,.2);
		border-radius: 16px;
		border:0.5px solid rgba(255,255,255,.3);
		box-sizing: border-box;
		overflow: hidden;
	}
	.content-1{
		.action{
			border-radius: 80rpx;
			background-color: rgba(255,255,255,0.2);
			.item{
				border-radius: 80rpx;
				padding: 12rpx 20rpx;
				margin: 0 5rpx;
				color: #FFFFFF;
			}
			.selected{
				background-color: rgba(255,255,255,0.5);
			}
		}
	}
</style>

